/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SeleniumTest;

import com.thoughtworks.selenium.SeleneseTestCase;
import java.util.regex.Pattern;

/**
 *
 * @author User
 */
public class LoginSeleneseTest extends SeleneseTestCase {

    @Override
	public void setUp() throws Exception {
            super.setUp("http://localhost:8080/","*firefox");
            selenium.setSpeed("2000"); //increase this for tests performed on slower connections
	}

        //tests login to valid user account
	public void testValidLogin() throws Exception {
		selenium.open("/GooWhere/");

                //username not in database
		selenium.type("username", "Rodg");
		selenium.type("password", "testpassword");
		selenium.click("btn_login2");
		verifyTrue(selenium.isTextPresent("not a valid username"));
		selenium.click("message_close");

                //username in database but incorrect password
		selenium.type("username", "Rodge");
		selenium.click("btn_login2");
		verifyTrue(selenium.isTextPresent("Incorrect password!"));
		selenium.click("message_close");

                //correct password but incorrect case
		selenium.type("password", "testpassworD2");
		selenium.click("btn_login2");
		verifyTrue(selenium.isTextPresent("Incorrect password!"));
		selenium.click("message_close");

                //correct password
		selenium.type("password", "testpassword2");
		selenium.click("btn_login2");
		selenium.waitForPageToLoad("30000");
		selenium.click("//img[@id='menu_account']");

                //successful login
		verifyTrue(selenium.isTextPresent("Rodge"));

	}

        //tests clues are displaying and subtracting money correctly
        //consider adding wait commands for the clues to load
        public void testValidClues() throws Exception {
		selenium.open("/GooWhere/");
		selenium.type("username", "Rodge");
		selenium.type("password", "testpassword2");
		selenium.click("btn_login2");
		selenium.waitForPageToLoad("30000");
		selenium.click("//img[@id='clue_control']");
		verifyTrue(selenium.isTextPresent("50.0"));
		selenium.click("clue_unlock_btn2");
		verifyTrue(selenium.isTextPresent("45"));
	}


        //tests Travel from 1 Waypoint to another and the money & time will be deducted.
        public void testValidTravel() throws Exception {
		selenium.open("/GooWhere/");
		selenium.type("username", "Rodge");
		selenium.type("password", "testpassword2");
		selenium.click("btn_login2");
		selenium.waitForPageToLoad("30000");
		selenium.click("go_east");
		verifyTrue(selenium.isTextPresent("50.0"));
		selenium.click("trans_taxi_data_third");
		verifyTrue(selenium.isTextPresent("40.96"));
	}

        //tests user able to view all the Transportations available at any location
        public void testViewingAvailableTransportation() throws Exception {
		selenium.open("/GooWhere/");
		selenium.type("username", "Rodge");
		selenium.type("password", "testpassword2");
		selenium.click("btn_login2");
		selenium.waitForPageToLoad("30000");

                //should display no valid locations to travel to
		selenium.click("go_north_west");
		verifyTrue(selenium.isTextPresent("No transportation available from such location."));
		selenium.click("info_ok_button");

                //should display Point Grey as possible destination
		selenium.click("go_east");
		verifyTrue(selenium.isTextPresent("Point Grey"));
		selenium.click("trans_window_bus");

                //should display no valid locations to travel to
		selenium.click("go_north_west");
		verifyTrue(selenium.isTextPresent("No transportation available from such location."));
		selenium.click("info_ok_button");

                //should display Vancouver City Hall as possible destination
		selenium.click("go_east");
                selenium.click("go_east");
		verifyTrue(selenium.isTextPresent("Vancouver City Hall"));
	}

}
